import {
	objDeepCopy,
	getDateString
} from "@/assets/js/common.js";
import commonObject from "@/assets/js/xm.js";
let Controller = {
	created() {
		this.init();
	},
	mounted() {

	},
	methods: {
		init() {
			this.getAllList(this, this.$route.query.number);
		},
		//
		onDialogEdit() {

		},
		//
		toggleTableDetail() {

		},
		//获取列表
		getAllList(that, orderNumber) {
			var apiTest = this.apiTest;
			this.$ajax({
				method: 'post',
				url: apiTest + '/supplier/whWarehouseDetail/outAndInDetails',
				// url:'/api/whWarehouseDetail/outAndInDetails',
				data: {
					condition: {
						number: orderNumber
					},
				}
			}).then((res) => {
				var data = res.data;
				if (data.status == 200) {
					that.Model.tab1TableData = [];
					var pagination = commonObject.paginationFunction(data.result);
					that.Model.paginationObject = objDeepCopy(pagination);
					var result = data.result;
					if (result) {
						result.status == '待入库' ? that.Model.refundStep.activeStep = 1 : that.Model.refundStep.activeStep = 2;
						that.Model.tabFormInline = [{
								label: '调拨入库单',
								value: result.number
							},
							{
								label: '入库单状态',
								value: result.status
							}
						]
						that.Model.tableFormInline = [{
								label: '入库单类型',
								value: result.type
							},
							{
								label: '调拨出库单号',
								value: result.originNumber
							},
							{
								label: '发货仓库',
								value: result.outWarehouseName
							},
							{
								label: '收货仓库',
								value: result.inWarehouseName
							},
							{
								label: '操作人',
								value: result.operatorName
							}
						]
						var obj = {}
						var dataInfo = result.shouldSaleGoodsInfoVos;
						if (dataInfo) {
							for (let i = 0; i < dataInfo.length; i++) {
								obj = objDeepCopy(dataInfo[i]);
								that.Model.tab1TableData.push(obj);
							}
						}


					}

				} else {

				}
			});
		},
		//返回上一级
		toInside() {
			this.$router.push({
				path: 'insideAllocationStore',
				query: {

				}
			});
		},
		toggleTableDetail(val) {
			const obj = this.Model[val];
			if (obj.flag === true) {
				this.Model[val].src = require('@/assets/img/icon_collapse.png');
				this.Model[val].flag = false;
			} else {
				this.Model[val].src = require('@/assets/img/icon_unfold.png');
				this.Model[val].flag = true;
			}
		},
		onDialogEdit(flag, val) {
			// 			this.Model.editDialogFlag = flag;
			// 			var saleId = this.Model.saleId;	
			// 			if (flag === false) return;
			// 			const arr = this.Model[val];
			// 			this.Model.editDialogType = val;
			// 			this.Model.editDialogFormData = _.cloneDeep(arr);
		},
		selectedHighlight(data) {
			// 如果选中则添加高亮样式
			if (this.Model.TableSelectData.indexOf(data.row) > -1) {
				return {
					"background-color": "#FEF6EE"
				};
				return {}
			}
		},
		//合计
		getSummaries(param) {
			var that = this;
			const {
				columns,
				data
			} = param;
			const sums = [];
			columns.forEach((column, index) => {
				if (index === 0) {
					sums[index] = '总价';
					return;
				} else if (index === 6 || index === 7 || index === 8 || index === 10) {
					const values = data.map(item => Number(item[column.property]));
					sums[index] = values.reduce((prev, curr) => {
						const value = Number(curr);
						if (!isNaN(value)) {
							return prev + curr;
						} else {
							return prev;
						}
					}, 0);
					if (index === 10) {
						that.Model.totleGoodCount = sums[index];
					} else {

					}

				} else {
					sums[index] = '/';
				}
			});

			return sums;
		},
		warehousing(row) {
			this.Model.warehousingDialogStatus = row.status;
			this.Model.warehousingDialogFlag = true;
		},
		handleSelectionChange(val) {
			this.Model.TableSelectData = val;

		},
		handleCurrentChange(val) {
			this.Model.pager.params.pageIndex = val;
		},
		handleSizeChange(val) {
			this.Model.pager.params.pageSize = val;
		},
		cardClick(color) {
			this.Model.cardSelected = color;
		},
		showChild(val) {
			this.Model.searchFromData = val;
		},
		toSearch(val) {
			console.log(val)
		},
		toClear(val) {
			this.Model.searchFromData = this.Model.defaultSearchFromData;
		},
		toExport(val) {
			console.log(val);
		},
		onTabChange(val) {
			console.log(val, this.Model.activeTab)
			switch (val) {
				case 1:
					break;
				case 2:
					break;
				case 3:
					break;
			}
		},
		tips(that, type, message) {
			let duration;
			type == 'success' ? duration = 3000 : duration = 10000;
			that.$message({
				message: message,
				type: type,
				duration: duration
			});
		},
	},
	watch: {
		$route: {
			handler(newValue, oldValue) {
				if (newValue.query.number) {
					this.getAllList(this, newValue.query.number);
				}
			},
			deep: true
		},

	},
	filters: {
		objFilters: function(value) {

		}
	}
}
export default Controller;
